﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;

namespace HRWEB.HtmlHelpers
{
    public static class MyHtmlHelpers
    {
        public static string FormatDateShort(this HtmlHelper html, DateTime? dateTime)
        {
            if (!dateTime.HasValue)
            {
                return "未知";
            }
            else
            {
                return dateTime.Value.ToString("yyyy-MM-dd");
            }
        }
        
        public static MvcHtmlString GetTableHeadRow(this HtmlHelper html, string[] content)
        {
            TagBuilder tr = new TagBuilder("tr");
            foreach (string s in content)
            {
                TagBuilder td = new TagBuilder("th");
                td.SetInnerText(s);
                tr.InnerHtml += td.ToString();
            }
            return new MvcHtmlString(tr.ToString());
        }
        public static MvcHtmlString GetTableHeadRowTD(this HtmlHelper html, string[] content)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string s in content)
            {
                TagBuilder td = new TagBuilder("th");
                td.SetInnerText(s);
                sb.Append(td.ToString());
            }
            return new MvcHtmlString(sb.ToString());
        }
        public static MvcHtmlString GetTableRow(this HtmlHelper html, string[] content)
        {
            TagBuilder tr = new TagBuilder("tr");
            foreach (string s in content)
            {
                TagBuilder td = new TagBuilder("td");
                td.SetInnerText(s);
                tr.InnerHtml += td.ToString();
            }
            return new MvcHtmlString(tr.ToString());
        }
        public static string FormatTDict(this HtmlHelper html, object tDict)
        {
            if (tDict == null)
            {
                return "";
            }
            else
            {
                return tDict.GetType().GetProperty("FName").GetValue(tDict, null).ToString();
            }
        }
    }
}